<?php
/**
 * @version		$Id: client_details.php 3 2011-12-16 20:19:15Z netix.mail@gmail.com $
 * @package		ALM Hoster
 * @desription	Web hosting and domain menager for resellers
 * @subpackage	Components
 * @copyright	Copyright (C) 2011 ALM Studio. All rights reserved.
 * @author		ALM Studio
 * @email		info@alm-studio.net
 * @link		http://alm-studio.net
 * @license		Commercial
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.modelform');
jimport('joomla.event.dispatcher');


class AlmHosterModelClient_details extends JModelForm
{
	protected $data;
	
	public function &getData()
	{
		
		$user	= JFactory::getUser();
		
		$db		= $this->getDbo();
		$query	= $db->getQuery(true);
		$query->select(
		'a.ClientId, a.ClientUser, a.ClientName, a.ClientAdress, a.ClientCity,'. 
		'a.ClientZip, a.ClientCountry, a.ClientCompany, a.ClientPhone, a.ClientMobile,'.
		'a.ClientFax, a.ClientCreated'				
		);
		$query->from('#__almh_clients AS a');	
		$query->where('a.ClientUser = ' . $user->get('id'));
		
		$query->select('u.username AS user');
		$query->join('LEFT', '#__users AS u ON u.id = a.ClientUser');
		
		$query->select('e.email AS email');
		$query->join('LEFT', '#__users AS e ON e.id = a.ClientUser');
	
		$query->select('c.CountryName AS country');
		$query->join('LEFT', '#__almh_countries AS c ON c.CountryId = a.ClientCountry');
								
		$db->setQuery((string) $query);

			if (!$db->query()) {
				JError::raiseError(500, $db->getErrorMsg());
				}
			$this->_data = $db->loadObject();
			
			return $this->_data;
	}
	
	public function getForm($data = array(), $loadData = true)
	{
		// Get the form.
		$form = $this->loadForm('com_almhoster.client_details', 'client_details', array('control' => 'jform', 'load_data' => $loadData));
		if (empty($form)) {
			return false;
		}

		return $form;
	}

	/**
	 * Method to get the data that should be injected in the form.
	 *
	 * @return	mixed	The data for the form.
	 * @since	1.6
	 */
	protected function loadFormData()
	{
		return $this->getData();
	}
}
